package pms.qa.service;

import java.sql.SQLException;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import java.util.*;


import pms.common.value.ProjectValue;
import pms.common.value.QaNewValue;
import pms.common.dao.ProjectDao;
import pms.common.dao.QaNewDao;
import pms.common.dao.ListSGDao;

import java.io.File;

public class QaNewServiceImpl implements QaNewService{
	
	private QaNewDao qaNewDao;
	private ListSGDao listSGDao;
	private ProjectDao projectDao;
	
	public ProjectDao getProjectDao() {
		return projectDao;
	}
	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}

	public QaNewDao getQaNewDao() {
		return qaNewDao;
	}

	public void setQaNewDao(QaNewDao qaNewDao) {
		this.qaNewDao = qaNewDao;
	}

	public ListSGDao getListSGDao() {
		return listSGDao;
	}

	public void setListSGDao(ListSGDao listSGDao) {
		this.listSGDao = listSGDao;
	}

	//プロジェクト
	public List<ProjectValue> getProjectList(){
		return projectDao.getProjectList();
	}
	// 所属テーマ
	@SuppressWarnings("unchecked")
	public List<HashMap> getFunctionArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
        return listSGDao.getFunctionArray();
    }
	//発生箇所
	@SuppressWarnings("unchecked")
	public List<HashMap> getPartArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("qa_part");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
           l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
           l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("QA_PART:" + l_array);
        return l_array;
    }
	// 段階
	@SuppressWarnings("unchecked")
	public List<HashMap> getLevelArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("qa_level");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
            l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
            l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("QA_LEVEL:" + l_array);
        return l_array;
    }
	// 緊急度
	@SuppressWarnings("unchecked")
	public List<HashMap> getKinkyuuArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
        SqlRowSet l_rs = listSGDao.getMasterData("qa_emergency");
        while(l_rs.next()) {
        	HashMap l_hashMap = new HashMap();
        	l_hashMap.put("master_id",l_rs.getString("MASTER_ID").trim());
            l_hashMap.put("master_group",l_rs.getString("MASTER_GROUP").trim());
            l_hashMap.put("master_value",l_rs.getString("MASTER_VALUE").trim());
        	l_array.add(l_hashMap);
        }
        System.out.println("QA_KINKYUU:" + l_array);
        return l_array;
    }

	// 問合先
	@SuppressWarnings("unchecked")
	public List<HashMap> getAskedArray() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {   
		List<HashMap> l_array = new ArrayList();
		l_array = listSGDao.getUserData();
		return l_array;
    }

	public void insertData(QaNewValue qaNewValue,File myFile,String fileName) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {

		System.out.println("file:"+ myFile);
		System.out.println("fileName:"+fileName);
		try {
			qaNewDao.doInsert(qaNewValue,myFile,fileName);
		}catch (Exception e) {
			e.printStackTrace();
		}
		qaNewValue = new QaNewValue();
	}
}
